package com.king.juc.shared.exercise;

/**
 * 账户类
 * @author king
 * @date 2020/10/28 18:26
 */
public class Account {

    private int money;

    public Account(int money){
        this.money = money;
    }

    public int getMoney(){
        return money;
    }

    public void setMoney(int money) {
        this.money = money;
    }

    // 转账
    public void transfer(Account target, int amount){
        synchronized (Account.class){
            if(this.money >= amount){
                this.setMoney(this.getMoney() - amount);
                target.setMoney(target.getMoney() + amount);
            }
        }
    }
}
